package com.white.algebra.domain;

import java.util.List;



public class Pager<T> {
    private List<T> bigList; // 集合，外界传入
    private int curentPageIndex = 1; // 当前页号，外界传入
    private int countPerpage = 4; // 每页条数，外界可以设定
    private int recordCount; // 总记录条数,外界传入
    private int pageCount; // 页数,自动算
    private int prePageIndex; // 上一页序号,自动算
    private int nextPageIndex; // 下一页序号,自动算
    private boolean firstPage; // 是否第一页,自动算
    private boolean lastPage; // 是否最后一页,自动算

    /**
     *
     * @param bigList 集合
     * @param curentPageIndex 当前页号
     * @param countPerpage 每页条数
     * @param recordCount 总记录条数
     */
    public void calculate(List<T> bigList,int curentPageIndex,int countPerpage,int recordCount) {
        this.bigList = bigList;
        this.curentPageIndex = curentPageIndex;
        this.countPerpage = countPerpage;
        this.recordCount = recordCount;

        // 上一页，下一页确定
        prePageIndex = curentPageIndex - 1;
        nextPageIndex = curentPageIndex + 1;
        // 计算页数
        if (recordCount % countPerpage == 0) {
            pageCount = recordCount / countPerpage;
        } else {
            pageCount = recordCount / countPerpage + 1;
        }
        // 是否第一页，最后一页
        if (curentPageIndex == 1) {
            firstPage = true;
        } else {
            firstPage = false;
        }
        if (curentPageIndex == pageCount) {
            lastPage = true;
        } else {
            lastPage = false;
        }

    }

    public void setCurentPageIndex(int curentPageIndex) {
        this.curentPageIndex = curentPageIndex;
    }

    public int getCurentPageIndex() {
        return curentPageIndex;
    }

    public List<T> getBigList() {
        return bigList;
    }

    public void setBigList(List<T> bigList) {
        this.bigList = bigList;
    }

    public int getCountPerpage() {
        return countPerpage;
    }

    public void setCountPerpage(int countPerpage) {
        this.countPerpage = countPerpage;
    }


    public int getPageCount() {
        return pageCount;
    }


    public int getRecordCount() {
        return recordCount;
    }

    public void setRecordCount(int recordCount) {
        this.recordCount = recordCount;
    }

    public int getNextPageIndex() {
        return nextPageIndex;
    }



    public int getPrePageIndex() {
        return prePageIndex;
    }



    public boolean isFirstPage() {
        return firstPage;
    }


    public boolean isLastPage() {
        return lastPage;
    }

    @Override
    public String toString() {
        return "Pager{" +
                "bigList=" + bigList +
                ", curentPageIndex=" + curentPageIndex +
                ", countPerpage=" + countPerpage +
                ", recordCount=" + recordCount +
                ", pageCount=" + pageCount +
                ", prePageIndex=" + prePageIndex +
                ", nextPageIndex=" + nextPageIndex +
                ", firstPage=" + firstPage +
                ", lastPage=" + lastPage +
                '}';
    }
}